<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>侦听属性</title>
</head>

<body>
    <div id="app">
        <div id="main" style="width: 400px;height:300px;"></div>
    </div>

    <script src="../vue.js"></script>
    <script src="../echarts.js"></script>

    <script>
        const app = new Vue({
            el: '#app',
            data: function () {
                return {
                    chart: null,
                    option: {
                        title: {
                            text: 'ECharts 入门示例'
                        },
                        tooltip: {},
                        legend: {
                            data: ['销量']
                        },
                        xAxis: {
                            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
                        },
                        yAxis: {},
                        series: {
                            name: '销量',
                            type: 'bar',
                            data: [5, 20, 36, 10, 10, 20]
                        }
                    }
                }
            },
            watch: {
                option: {
                    handler: function(val) {
                        this.chart && this.chart.setOption(val)
                    },
                    deep: true
                }
            },
            mounted() {
                this.chart = echarts.init(document.getElementById('main'))
                this.chart.setOption(this.option)

                setTimeout(() => {
                    this.option.series.data = [5, 20, 36, 10, 10, 20].map(item => item * 2)
                }, 5000)
            }
        })
    </script>
</body>

</html>